package com.itheima.dao;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface MenuDao {
    @Select("SELECT id,NAME,linkUrl,LEVEL,description  FROM t_menu WHERE LEVEL=1 ")
    Page<Map> findByPage();
    @Select("SELECT name value,name label  FROM t_menu WHERE LEVEL=1 ")
    List<Map> findAllMenu();
    @Select("SELECT id,NAME,linkUrl,LEVEL,description FROM t_menu WHERE parentMenuId=#{id} ")
    List<Map> findChildrenById(Integer id);
    @Insert("insert into t_menu(name,description,level,parentMenuId) values(#{name},#{description},#{level},#{parentMenuId})")
    void add(Map menu);
    @Insert("insert into t_menu(name,path,description,priority,level) values(#{name},#{path},#{description},#{priority},#{level})")
    void addFaMenu(Map menu);
    @Select("SELECT MAX(path) FROM t_menu")
    int findMaxPath();
    @Select("select id from t_menu where name=#{faMenuName}")
    Integer findIdByMenuName(String faMenuName);
    @Select("select name,description from t_menu where id=#{id}")
    Map findNameById(Integer id);
    @Update("update  t_menu set name=#{name},description=#{description},level=#{level},parentMenuId=#{parentMenuId} where id=#{id}")
    void edit( Map map);
    @Update("update  t_menu set name=#{name},description=#{description},path=#{path},priority=#{priority} where id=#{id}")
    void editFaMenu( Map map);
    @Select("SELECT parentMenuId FROM t_menu WHERE id=#{id}")
    Integer findParentIdById(int id);
    @Select("SELECT id FROM t_menu WHERE parentMenuId=#{parentMenuId}")
    List<Integer> findChildRensIdById(int id);
    @Delete("delete from t_menu where id=#{id}")
    void deleteMenuById(int id);
    @Select("SELECT linkUrl FROM t_menu WHERE id=#{id}")
    String findlinkUrlById(int id);
}
